const express = require('express')
const path = require('path')
const bodyParser = require('body-parser')
const session = require('express-session')
const cors = require('cors');
const router = require('./routes/user')

const app = express()
app.engine('html',require('express-art-template'))
app.set('views', path.join(__dirname, './views'))
app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())
app.use('/public', express.static(path.join(__dirname, './public')))
app.use('/node_modules', express.static(path.join(__dirname, './node_modules')))
app.use(cors());
app.use(session({
  secret: 'keyboard cat', //配置加密字符串
  resave: false,
  saveUninitialized: true //默认分配钥匙

}))
app.use(router)
//配置一个全局错误处理中间件
app.use((err, req, res, next) => {
  res.status(500).json({
    err_code: 500,
    message: '错误'
  })
})
app.listen(3000, () => {
  console.log('SELF-BLOG');
})
